package com.atmc.controller;

import com.atmc.bean.Bill;
import com.atmc.bean.Code;
import com.atmc.bean.Supplier;
import com.atmc.bean.User;
import com.atmc.service.BillService;
import com.atmc.service.OpenFeignService;
import com.atmc.service.SupplierService;
import com.atmc.service.UserService;
import org.bouncycastle.math.raw.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class UserFeignController {
    @Autowired
    OpenFeignService openFeignService;


    @Autowired
    UserService userService;

    //首页跳转到用户管理信息
    @RequestMapping("/user/member-del")
    public String toMemberdel(Model model) {
        List<User> list = openFeignService.userList();
        model.addAttribute("msg",list);

        return "user/member-del";
    }
    //首页跳转到用户管理信息
    @RequestMapping("/user/member-list")
    public String toMemberlist(Model model) {
        List<User> list = openFeignService.userList();
        model.addAttribute("msg",list);

        return "user/member-list";
    }
    //添加一条用户记录
    @RequestMapping("/user/useradd")
    public String toarticleList(@RequestParam("user_name") String user_name, @RequestParam("user_sex") String user_sex,
                                @RequestParam("user_birth") String user_birth, @RequestParam("user_type") String user_type
                               , Model model) {
            User user=new User(null,user_name,user_sex,user_birth,user_type,null,null);
        userService.insertOne(user);
        List<User> list = openFeignService.userList();
        model.addAttribute("msg",list);
        return "bill/insertsuccess";

    }
    //跳转到修改一条用户的页面
    @RequestMapping("/touserupdate/{user_name}")
    public String touserupdate(@PathVariable("user_name")String user_name,Model model){
        model.addAttribute("user_name",user_name);
        return "user/updateUser";
    }
    //修改一条用户记录
    @RequestMapping("/user/updateuser")
    public String toupdateuser(@RequestParam("user_name") String user_name, @RequestParam("user_sex") String user_sex,
                               @RequestParam("user_birth") String user_birth, @RequestParam("user_type") String user_type
                                 ,Model model ){
        User user=new User(null,user_name,user_sex,user_birth,user_type,null,null);
        userService.updateOne(user);
        List<User> list = openFeignService.userList();
        model.addAttribute("msg",list);
        return "user/member-list";
    }
    //删除一条用户记录
    @RequestMapping("/touserdelete/{user_id}")
    public String touserdelete(@PathVariable("user_id")Integer user_id,Model model){
        userService.deleteOne(user_id);
        List<User> list = openFeignService.userList();
        model.addAttribute("msg",list);
        return "user/member-list";
    }
    //查询一条用户信息
    @RequestMapping("/toUserselectOne")
    public String toUserselectOne(@RequestParam("user_name")String user_name,Model model){
        User list = userService.selectOne(user_name);
        model.addAttribute("msg",list);
        return "user/member-list";
    }


}
